<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box{
				width: 100px;
				height: 100px;
				background-color: #009F95;
				position: absolute;
				left: 100px;
			}
		</style>
	</head>
	<body>
		<div id="box">
			
		</div>
		<button id="start">开始</button>
		<script type="text/javascript">
			var oBtn = document.getElementById("start")
			var oBox = document.getElementById("box")
//			var timer = null
            //把timer加到oBox对象上
            oBox.timer = null
			oBtn.onclick = function  () {
				//undefined
				console.log(oBox.timer)
				clearInterval(oBox.timer)
				timer = setInterval(function  () {
					var attrValue = parseInt(getStyle(oBox,"left")) + 10 
					if (attrValue > 500) {
						attrValue = 500
					}
					oBox.style.left = attrValue + "px"
					//添加一个目标点
					if (attrValue == 500) {
						clearInterval(oBox.timer)
						oBox.timer = null
					}
				},100)
//				oBox.style.left = parseInt(getStyle(oBox,"left")) + 10 + "px"
			}
			function getStyle(obj,attr){
				return window.getComputedStyle ? window.getComputedStyle(obj)[attr] : obj.currentStyle[attr]
			}
		</script>
	</body>
</html>
